home *** CD-ROM | disk | FTP | other *** search
- /************************************/
- /* File: Demo.c
- Function: Demo Window functions */
- /************************************/
- /* #include files */
- #include "General.h"
- #include "Demo.h"
- #include "Transition.h"
-
- /* global variables */
- int dChk;
- int pChk;
- int cChk;
- int wipeMode;
- int wipePart;
- WindowPtr MyWindow;
-
- /* static variables and function prototypes */
- static void Do_A_Button(ControlHandle theControl);
-
- static Rect srcR = {21, 11, 141, 141};
- static Rect dstR = {21, 261,141, 391};
- static long elapsedTime;
-
- /************************************/
- /* routines:
- • void Init_Demo()
- • void UpDate_Demo(whichWindow)
- • void Open_Demo()
- • static void Do_A_Button(theControl)
- • void Do_Demo(myEvent)
- */
- /************************************/
-
- /************************************/
- /* void Init_Demo()
- initializes demo window */
- /************************************/
- void Init_Demo()
- {
- MyWindow = NIL;
- dChk = pChk = cChk = 1;
- wipeMode = srcCopy;
- wipePart = 1;
- elapsedTime = 0;
- } /* void Init_Demo() */
-
- /************************************/
- /* void UpDate_Demo(whichWindow)
- updates demo window */
- /************************************/
- void UpDate_Demo(whichWindow)
- WindowPtr whichWindow;
- {
- WindowPtr SavePort;
- Rect tempRect;
- Str255 sTemp;
- Str255 destinationStr = "\pDestination=>";
- Str255 sourceStr = "\p<=Source";
-
- if ((MyWindow != NIL) && (MyWindow == whichWindow)) { /* update demo window */
- GetPort(&SavePort);
- SetPort(MyWindow);
-
- /* draw frames */
- SetRect(&tempRect, 260,20,392,142);
- FrameRect(&tempRect);
- SetRect(&tempRect, 10,20,142,142);
- FrameRect(&tempRect);
-
- /* draw source image */
- InsetRect(&tempRect, 5, 5);
- FrameRect(&tempRect);
- FillRect(&tempRect, ltGray);
- SetRect(&tempRect, 20,112,40,132);
- PenSize(4, 2);
- PenMode(patBic);
- FrameOval(&tempRect);
- FillOval(&tempRect, dkGray);
- PenMode(patOr);
- PenSize(2,2);
- MoveTo(30, 30);
- LineTo(35, 60);
- LineTo(120, 120);
- PenNormal();
- SetRect(&tempRect, 110,30,130,50);
- FrameRect(&tempRect);
- FillRect(&tempRect, white);
-
- /* Draw text stuff */
- TextFont(systemFont);
- SetRect(&tempRect, 160,120,250,140);
- TextBox(&destinationStr[1], destinationStr[0], &tempRect, teJustLeft);
- SetRect(&tempRect, 150,30,210,50);
- TextBox(&sourceStr[1], sourceStr[0], &tempRect, teJustLeft);
-
- /* Draw information */
- SetRect(&tempRect, 10, 145, 300, 210);
- FillRect(&tempRect, white);
- MoveTo(10, 160);
- switch (dChk) {
- case DoWipeTopBottm:
- DrawString("\pWipe Top=>Down");
- MoveTo(10, 175);
- DrawString("\pPartitions:");
- NumToString((long) wipePart, &sTemp);
- MoveTo(80, 175);
- DrawString(sTemp);
- break;
- case DoWipeBottomTop:
- DrawString("\pWipe Down=>Up");
- MoveTo(10, 175);
- DrawString("\pPartitions:");
- NumToString((long) wipePart, &sTemp);
- MoveTo(80, 175);
- DrawString(sTemp);
- break;
- case DoWipeLeftRight:
- DrawString("\pWipe Left=>Right");
- MoveTo(10, 175);
- DrawString("\pPartitions:");
- NumToString((long) wipePart, &sTemp);
- MoveTo(80, 175);
- DrawString(sTemp);
- break;
- case DoWipeRightLeft:
- DrawString("\pWipe Right=>Left");
- NumToString((long) wipePart, &sTemp);
- MoveTo(80, 175);
- DrawString(sTemp);
- MoveTo(10, 175);
- DrawString("\pPartitions:");
- break;
- case DoPageFlipDown:
- DrawString("\pPageFlipDown");
- NumToString((long) wipePart, &sTemp);
- MoveTo(80, 175);
- DrawString(sTemp);
- MoveTo(10, 175);
- DrawString("\pPartitions:");
- break;
- case DoPageFlipRight:
- DrawString("\pPageFlipRight");
- NumToString((long) wipePart, &sTemp);
- MoveTo(80, 175);
- DrawString(sTemp);
- MoveTo(10, 175);
- DrawString("\pPartitions:");
- break;
- case DoIrisWipe:
- DrawString("\pIris Wipe");
- MoveTo(10, 175);
- switch (pChk) {
- case 1:
- DrawString("\pCircle in");
- break;
- case 2:
- DrawString("\pCircle out");
- break;
- case 3:
- DrawString("\pTriangle");
- break;
- case 4:
- DrawString("\pOdd Shape");
- break;
- }
- break;
- case DoFadeWipe:
- DrawString("\pFade Wipe");
- MoveTo(10, 175);
- switch (pChk) {
- case 1:
- DrawString("\pRandom 1");
- break;
- case 2:
- DrawString("\pRandom 2");
- break;
- case 3:
- DrawString("\pDiagonal");
- break;
- case 4:
- DrawString("\pVertical");
- break;
- }
- break;
- }
-
- MoveTo (10, 190);
- switch (cChk) {
- case 1:
- DrawString("\psrcCopy");
- break;
- case 2:
- DrawString("\psrcOr");
- break;
- case 3:
- DrawString("\psrcXor");
- break;
- case 4:
- DrawString("\psrcBIC");
- break;
- case 5:
- DrawString("\pnotSrcCopy");
- break;
- case 6:
- DrawString("\pnotSrcOr");
- break;
- case 7:
- DrawString("\pnotSrcXor");
- break;
- case 8:
- DrawString("\pnotSrcBic");
- break;
- }
-
- MoveTo(10, 205);
- DrawString("\pTime in ticks:");
- NumToString((long) elapsedTime, &sTemp);
- MoveTo(100, 205);
- DrawString(sTemp);
-
- TextFont(applFont);
-
- DrawControls(MyWindow);
- SetPort(SavePort);
- } /* update demo window */
- } /* void UpDate_Demo(whichWindow) */
-
- /************************************/
- /* void Open_Demo()
- opens demo window */
- /************************************/
- void Open_Demo()
- {
- Rect tempRect;
- ControlHandle tempControl;
-
- if (MyWindow == NIL) { /* create demo window */
- MyWindow = GetNewWindow(1,NIL, WindowInFront);
- tempRect = MyWindow->portRect;
- PositionRect(&tempRect, &(screenBits.bounds), CENTER, CENTER);
- MoveWindow(MyWindow, tempRect.left, tempRect.top, TRUE);
- SetPort(MyWindow);
-
- /* Make buttons */
- tempControl = GetNewControl(TransitionBtnRef,MyWindow);
- tempControl = GetNewControl(EraseImageBtnRef,MyWindow);
- tempControl = GetNewControl(DrawImageBtnRef,MyWindow);
-
- ShowWindow(MyWindow);
- SelectWindow(MyWindow);
- } /* create demo window */
- else
- SelectWindow(MyWindow); /* show demo window */
- } /* void Open_Demo() */
-
- /************************************/
- /* static void Do_A_Button(theControl)
- handles button in demo window */
- /************************************/
- static void Do_A_Button(theControl)
- ControlHandle theControl;
- {
- short RefCon;
- Rect tempRect;
- Rect infoRect = {145, 10, 300, 210};
- PolyHandle thePoly;
- RgnHandle maskRgn, irisRgn, iris2Rgn;
- long startTicks, stopTicks;
-
- HiliteControl(theControl, 10);
-
- RefCon = GetCRefCon(theControl);
- tempRect = dstR;
-
- switch (RefCon) { /* Button Switch */
- case TransitionBtnRef: /* transition button */
- switch (dChk) { /* transition switch */
- case DoWipeTopBottm:
- startTicks = TickCount();
- WipeTopBottom(&(MyWindow->portBits), &(MyWindow->portBits), &srcR, &dstR, wipeMode, NIL, wipePart, 0L);
- stopTicks = TickCount();
- break;
-
- case DoWipeBottomTop:
- startTicks = TickCount();
- WipeBottomTop(&(MyWindow->portBits), &(MyWindow->portBits), &srcR, &dstR, wipeMode, NIL, wipePart, 0L);
- stopTicks = TickCount();
- break;
-
- case DoWipeLeftRight:
- startTicks = TickCount();
- WipeLeftRight(&(MyWindow->portBits), &(MyWindow->portBits), &srcR, &dstR, wipeMode, NIL, wipePart, 0L);
- stopTicks = TickCount();
- break;
-
- case DoWipeRightLeft:
- startTicks = TickCount();
- WipeRightLeft(&(MyWindow->portBits), &(MyWindow->portBits), &srcR, &dstR, wipeMode, NIL, wipePart, 0L);
- stopTicks = TickCount();
- break;
-
- case DoIrisWipe:
- maskRgn = NewRgn();
- RectRgn(maskRgn, &dstR);
- iris2Rgn = NewRgn();
- irisRgn = NewRgn();
- OpenRgn();
- switch (pChk) { /* iris switch */
- case 1:
- FrameOval(&tempRect);
- CloseRgn(irisRgn);
- InsetRgn(irisRgn, -20, -20);
- CopyRgn(irisRgn, iris2Rgn);
- InsetRgn(irisRgn, -1, -1);
- DiffRgn(irisRgn, iris2Rgn, irisRgn);
- break;
- case 2:
- FrameOval(&tempRect);
- CloseRgn(irisRgn);
- InsetRgn(irisRgn, 40, 40);
- break;
- case 3:
- MoveTo(261, 21);
- LineTo(261, 141);
- LineTo(391, 141);
- LineTo(261, 21);
- CloseRgn(irisRgn);
- OffsetRgn(irisRgn, 10, -10);
- CopyRgn(irisRgn, iris2Rgn);
- InsetRgn(irisRgn, -1, -1);
- DiffRgn(irisRgn, iris2Rgn, irisRgn);
- break;
- case 4:
- SetRect(&tempRect, 281,41,301,61);
- FrameOval(&tempRect);
- SetRect(&tempRect, 351,41,371,61);
- FrameRect(&tempRect);
- MoveTo(281, 121);
- LineTo(371, 121);
- CloseRgn(irisRgn);
- CopyRgn(irisRgn, iris2Rgn);
- InsetRgn(irisRgn, -1, -1);
- DiffRgn(irisRgn, iris2Rgn, irisRgn);
- break;
- } /* iris switch */
-
- startTicks = TickCount();
- Iris(&(MyWindow->portBits), &(MyWindow->portBits), &srcR, &dstR, wipeMode, maskRgn, irisRgn, 0L);
- stopTicks = TickCount();
- DisposeRgn(irisRgn);
- DisposeRgn(iris2Rgn);
- DisposeRgn(maskRgn);
- break;
-
- case DoFadeWipe:
- startTicks = TickCount();
- FadePat(&(MyWindow->portBits), &(MyWindow->portBits), &srcR, &dstR, wipeMode, NIL, pChk * 1000, 8, 0L);
- stopTicks = TickCount();
- break;
-
- case DoPageFlipDown:
- startTicks = TickCount();
- PageFlipDown(&(MyWindow->portBits), &(MyWindow->portBits), &srcR, &dstR, NIL, pChk, 0L);
- stopTicks = TickCount();
- break;
-
- case DoPageFlipRight:
- startTicks = TickCount();
- PageFlipRight(&(MyWindow->portBits), &(MyWindow->portBits), &srcR, &dstR, NIL, pChk, 0L);
- stopTicks = TickCount();
- break;
- } /* transition switch */
- elapsedTime = stopTicks - startTicks;
- InvalRect(&infoRect);
- break;
-
- case EraseImageBtnRef: /* erase button */
- FillRect(&dstR, white);
- break;
-
- case DrawImageBtnRef: /* Draw image button */
- FillRect(&dstR, white);
- thePoly = OpenPoly();
- MoveTo(265, 25);
- LineTo(265, 130);
- LineTo(300, 75);
- LineTo(265, 25);
- ClosePoly();
- PenSize(4, 2);
- PenPat(dkGray);
- FramePoly(thePoly);
- FillPoly(thePoly, ltGray);
- KillPoly(thePoly);
- PenNormal();
- SetRect(&tempRect, 350, 30, 380, 100);
- PaintRoundRect(&tempRect, 5, 5);
- PenMode(patCopy);
- TextMode(srcXor);
- MoveTo(300, 60);
- DrawString("\pThis is NEAT");
- TextMode(srcOr);
- PenNormal();
- break;
-
- default:
- break;
- } /* Button Switch */
-
- HiliteControl(theControl, 0);
- } /* static void Do_A_Button(theControl) */
-
- /************************************/
- /* void Do_Demo(myEvent)
- handles events on demo window */
- /************************************/
- void Do_Demo(myEvent)
- EventRecord *myEvent;
- {
- short code;
- WindowPtr whichWindow;
- Point myPt;
- ControlHandle theControl;
-
- if (MyWindow != NIL) { /* demo window only */
- code = FindWindow(myEvent->where, &whichWindow);
-
- if ((MyWindow == whichWindow) &&
- (myEvent->what == mouseDown) && (code == inContent)) { /* mousedown */
- myPt = myEvent->where;
- GlobalToLocal(&myPt);
- code = FindControl(myPt, whichWindow, &theControl);
- if (code == inButton) /* in button */
- Do_A_Button(theControl);
- }
- }
- } /* void Do_Demo(myEvent) */